/*!
 * FileName: luogu-4408.cpp
 * This Problem is on luogu. The ID of the problem is 4408. 
 * Copyright(c) 2019 Shu_Yu_Mo
 * MIT Licensed
 * Luogu: https://www.luogu.org/space/show?uid=44615
 * Github: https://github.com/oldsuold/
 * Gitee: https://gitee.com/Shu_Yu_Mo/
 * These words were created by an amazing tool written by Shu_Yu_Mo.
 */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#define inf 0x7fffffff
#define int long long
using namespace std;
const int _N = 200100;
const int _M = _N;
inline int read()
{
    char c = getchar(); int sign = 1; int x = 0;
    while(c > '9' || c < '0') { if(c=='-')sign = -1; c = getchar(); } 
    while(c <= '9' && c >= '0') { x *= 10; x += c - '0'; c = getchar(); }
    return x * sign;
}
void swap(int & x, int & y)
{
	int t = x;
	x = y;
	y = t;
}
int n, m; 
//struct edges{
//	int node;
//	int w;
//	int nxt;
//}edge[_M];
//int head[_N];
//int tot = 0;
//void add(int u, int v, int w)
//{
//	printf("add %d to %d w = %d\n", u, v, w);
//	edge[++tot].nxt = head[u];
//	edge[tot].node = v;
//	edge[tot].w = w;
//	head[u] = tot;
//	
//	
////	edge[++tot].nxt = head[u];
////	edge[tot].node = v;
////	edge[tot].w = w;
////	head[u] = tot;
//}
struct edges{
    int node;
    int w;
    int nxt;
}edge[_M << 1];
int tot = 0;
int head[_N];
void add(int u, int v, int w)
{
    edge[++tot].nxt = head[u];
    edge[tot].node = v;
    edge[tot].w = w;
    head[u] = tot;
}
bool vis[_N];
int dist[_N];
void dfs(int nowNode)
{
//	if(vis[edge[i].node]) continue;
	vis[nowNode] = true;
	for(register int i = head[nowNode];i;i = edge[i].nxt)
	{
		if(vis[edge[i].node]) continue;
		dist[edge[i].node] = dist[nowNode] +  edge[i].w;
		dfs(edge[i].node);
	}
}
float r;
int dist_[_N];
int tot_ = 0;
int MaxId2, MaxId;
int MaxDeep = -inf;
bool flag = false;
int path[_N];
bool inPath[_N];
int path_w[_N];
void dfsForPath(int k,int deepth, int w)
{
	vis[k] = true;
	path[deepth] = k;
	path_w[deepth] = w;
	if(k == MaxId2) { MaxDeep = deepth;flag = true;return; }
	for(register int i = head[k];i;i = edge[i].nxt)
	{
		int SonNode = edge[i].node;
		if(vis[SonNode]) continue;
		dfsForPath(SonNode, deepth + 1, edge[i].w); 
		if(flag)return;
	}
}
int dfsLast(int k)
{
	int longest = 0;
	vis[k] = true;
	for(register int i = head[k];i;i = edge[i].nxt)
	{
		int SonNode = edge[i].node;
		if(inPath[SonNode] || vis[SonNode]) continue;
		longest = max(longest, dfsLast(SonNode) + edge[i].w);
	}
	return longest;
}
signed main()
{	
//	freopen("test.in.txt", "r", stdin);
	memset(vis, false, sizeof(vis));
	n = read(), m = read();
	for(register int i = 1;i <= m;i++)
	{
		int tmpx = read(), tmpy = read(), tmpz = read();
		add(tmpx, tmpy, tmpz);
		add(tmpy, tmpx, tmpz);
	}
	int MaxDis = 0;
	memset(dist, 0, sizeof(dist));
	dfs(1);
	for(register int i = 1;i <= n;i++)
	{
//		printf("%d ", dist[i]);
		if(dist[i] > MaxDis)
		{
			MaxDis = dist[i];
			MaxId = i;
		}
	}
//	printf("%d\n", MaxId);
	memset(dist, 0, sizeof(dist));
	memset(vis, false, sizeof(vis));
	dfs(MaxId);
	int MaxDis2 = 0;
	for(register int i = 1;i <= n;i++)
	{
		if(dist[i] > MaxDis2)
		{
			MaxDis2 = dist[i];
			MaxId2 = i;
		}
	}
//	printf("MaxDist = %d, node = %d ,%d\n", MaxDis2, MaxId2, MaxId);
	memset(vis, false, sizeof(vis));
	dfsForPath(MaxId, 1, 0);
//	for(register int i = 1;i <= MaxDeep;i++)
//		printf("%d ", path[i]);
	memset(inPath, false, sizeof(inPath));
	for(register int i = 1;i <= MaxDeep;i++)
		inPath[path[i]] = true;
	int ans = -inf;
	memset(vis, 0, sizeof(vis));
	int now = 0;
	for(register int i = 1;i <= MaxDeep;i++)
	{
		now += path_w[i];
		int tmp = min(now, MaxDis2 - now);
		int kk = dfsLast(path[i]);
		ans = max(ans, kk + tmp + MaxDis2);
	}
	printf("%lld", ans);
	
    return 0;
}
/*
4 3
1 2 1
2 4 1
2 3 2

*/
